package org.news.web;

import javax.servlet.http.HttpSessionAttributeListener;
import javax.servlet.http.HttpSessionBindingEvent;

import org.apache.log4j.Logger;

public class SessionAttributeAccessListener implements
        HttpSessionAttributeListener {
    private final Logger log = Logger
            .getLogger(SessionAttributeAccessListener.class);

    @Override
    public void attributeAdded(HttpSessionBindingEvent arg0) {
        // if ("admin".equals(arg0.getName())) // 针对用户登录做判断
        log.info("变量 " + arg0.getName() + " 被添加到session中，其类型为 "
                + arg0.getValue().getClass().getName());
    }

    @Override
    public void attributeRemoved(HttpSessionBindingEvent arg0) {
        // if ("admin".equals(arg0.getName())) // 针对用户下线做判断
        log.info("变量 " + arg0.getName() + " 被从session中移除 ");
    }

    @Override
    public void attributeReplaced(HttpSessionBindingEvent arg0) {
        log.info("session中的变量 " + arg0.getName() + " 被替换，其旧值为 "
                + arg0.getValue());
    }
}
